package cn.itsource.pethome.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 添加拦截器到配置中
 */
@Configuration
public class WebConfigurer implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns("/**") 表示拦截所有的请求，
        // excludePathPatterns("/login", "/register")
        registry
            .addInterceptor(loginInterceptor)//添加拦截器
            .addPathPatterns("/**")//要拦截的路径
            .excludePathPatterns(
                    "/logininfo/account","/register/**","/login/**","/fast/**","/shop/**"
                    ,"/vcode/**","/shopActivation/**","/user/activation/","/swagger-ui.html","/swagger-resources/**","/webjars/**");//不拦截的路径。表示除了登陆与注册之外，因为登陆注册不需要登陆也可以访问
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}